#!/bin/bash

. include/conf.sh
OUTPUTPATH=/tmp/$(rand)

cat zone/zone.head > ${OUTPUTPATH}/wr-zone
echo -n '' > ${OUTPUTPATH}/wr-zone-normal
echo -n '' > ${OUTPUTPATH}/wr-zone-rr

cat conf/network.conf | grep '^S:' |
while read line
do
        if [ `echo $line | cut -d ':' -f 5 | grep -c 'r'` != 0 ]
        then
                echo -e "`echo $line | cut -d ':' -f 2 | tr -d \"\n\"`\tIN\tA\t`echo $line | cut -d ':' -f 3 | tr -d \"\n\"`" >> ${OUTPUTPATH}/wr-zone-normal
                echo -e "irc\tIN\tA\t`echo $line | cut -d ':' -f 3 | tr -d \"\n\"` ; `echo $line | cut -d ':' -f 2 | tr -d \"\n\"`" >> ${OUTPUTPATH}/wr-zone-rr
        fi
done

cat ${OUTPUTPATH}/wr-zone > wyldryde.org.hosts
cat ${OUTPUTPATH}/wr-zone-normal >> wyldryde.org.hosts
echo >> wyldryde.org.hosts
echo '; Round Robin' >> wyldryde.org.hosts
cat ${OUTPUTPATH}/wr-zone-rr >> wyldryde.org.hosts

cat wyldryde.org.hosts

echo
echo

#sudo /usr/sbin/rndc reload wyldryde.org

rm -r ${OUTPUTPATH}
